package com.cube.dp.adapter;

import com.cube.dp.adapter.fs.custom.IFileOperationService;
import com.cube.dp.adapter.fs.third.dto.FileDownloadDto;
import com.cube.dp.adapter.fs.third.dto.FileDownloadForStreamDto;
import com.cube.dp.adapter.fs.third.dto.FileUploadDto;
import com.cube.dp.adapter.fs.third.dto.FileUploadForStreamDto;

/**
 * @author litb
 * @date 2022/5/21 16:23
 * <p>
 * 文件适配器,将第三方文件服务与自研文件服务适配
 */
public class CustomFileOperationAdaptor implements FileOperationAdaptee {

    private final IFileOperationService customFileOperationService;

    public CustomFileOperationAdaptor(IFileOperationService customFileOperationService) {
        this.customFileOperationService = customFileOperationService;
    }

    @Override
    public String upload(FileUploadDto dto) {
        return customFileOperationService.upload(to(dto));
    }

    @Override
    public String upload4Stream(FileUploadForStreamDto streamDto) {
        return customFileOperationService.upload4Stream(to(streamDto));
    }

    @Override
    public FileDownloadDto download(String fileId) {
        return to(customFileOperationService.download(fileId));
    }

    @Override
    public FileDownloadForStreamDto download4Stream(String fileId) {
        return to(customFileOperationService.download4Stream(fileId));
    }
}
